package com.xywl.escort.adapter.provider;

import android.view.View;
import android.widget.ImageView;

import com.alibaba.android.arouter.launcher.ARouter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chad.library.adapter.base.annotation.ItemProviderTag;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.xywl.escort.R;
import com.xywl.escort.adapter.HomeRvAdapter;
import com.xywl.escort.bean.NoticeResp.DataBean.ListBean;
import com.xywl.escort.entity.NormalMultipleEntity;
import com.xywl.escort.widget.NoticeView;

import java.util.List;

@ItemProviderTag(
        viewType = HomeRvAdapter.TYPE_NOTICE,
        layout = R.layout.item_notice_view
)
public class NoticeItemProvider extends BaseItemProvider<NormalMultipleEntity, BaseViewHolder> {
    @Override
    public void convert(BaseViewHolder helper, NormalMultipleEntity data, int position) {
        NoticeView noticeView = helper.getView(R.id.notice_view);

        final List<ListBean> noticeList = data.noticeData;

        noticeView.addNotice(noticeList);
        if (null != noticeList && noticeList.size() > 1) {
            noticeView.startFlipping();
        }

        noticeView.setOnNoticeClickListener(new NoticeView.OnNoticeClickListener() {
            @Override
            public void onNoticeClick(int position, ListBean notice) {
                if (null != noticeList) {
                    ListBean bean = noticeList.get(position);
                    String title = bean.title;
                    String content = bean.content;
                    String time = bean.createTime;
                    ARouter.getInstance()
                            .build("/xy/notice/detail")
                            .withString("title", title)
                            .withString("content", content)
                            .withString("time", time)
                            .navigation();
                }
            }
        });

        ImageView imgMore = helper.getView(R.id.img_more);
        imgMore.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ARouter.getInstance().build("/xy/notice/list").navigation();
            }
        });
    }

    @Override
    public void onClick(BaseViewHolder helper, NormalMultipleEntity data, int position) {
    }

    @Override
    public boolean onLongClick(BaseViewHolder helper, NormalMultipleEntity data, int position) {
        return false;
    }
}
